<template>
  <div>
    <div class="" v-for="row in meterinfo">
      <meter-info :meter="row" :usertype="usertype" :gasproperties="gasproperties" @self-valid='valida'
      @delete-meter="deleteMeter($index)" :f_userinfo_id="f_userinfo_id"></meter-info>
    </div>
    <div class="panel panel-default auto text-center" @click="addMeter()" style="cursor: pointer;">
      <img :src="imgmeter" alt="图片加载失败" class="img-rounded" style="width: 50px;margin:10px;">
    </div>
  </div>
</template>

<script>
import * as Util from '../Util'

export default {
  title: '表具信息',
  data () {
    return {
      pricenames: [],
      imgsrc: '/images/mainicon/biaopan.png',
      imgmeter: '/images/mainicon/addmeter.png'
    }
  },
  // props: ['meterinfo', 'usertype', 'gasproperties', 'metervalid'],

  props: {
    meterinfo: {},
    usertype: {},
    gasproperties: {},
    metervalid: {
      twoWay: true
    },
    f_userinfo_id: {}
  },
  ready () {
    console.log('表具信息，，，，', this.meterinfo)
  },
  methods: {
    isNull (value) {
      return value && value.length > 0
    },
    addMeter () {
      this.meterinfo.push({
        gasbrand: '',
        gasmodel: '',
        pricetype: '',
        f_inputtor: '',
        f_meter_base: 0,
        f_aroundmeter: '左表',
        f_install_date: Util.toStandardTimeString(),
        f_gas_date: Util.toStandardTimeString(),
        f_changetube_date: '',
        f_position: [''],
        pricename: ['']
      })
    },
    // 清楚表具信息

    clearMeter () {
      this.meterinfo = []
    },
    deleteMeter (index) {
     this.meterinfo.splice(index, 1)
   },
   valida () {
     for (var i = 0; i < this.meterinfo.length; i++) {
       if (!this.meterinfo[i].valid) {
         this.metervalid = false
         return
       }
     }
     this.metervalid = true
     return
   }
  }
}
</script>
<style lang="less">
  .user-meter-padding {
    .form-group {
      > div {
        padding-right: 5px;
      }
    }
  }
</style>
